/* eslint-disable max-lines */
import React from 'react';
import {Spin, Card, Button, Row, Col, Form, Table, Popconfirm} from 'antd';
import PropTypes from 'prop-types';
import routes from './routes';
import {FORM_OPTIONS, FORM_ROW_OPTIONS, TABLE, DATETIME_FORMAT, FIXED_COLUMN_WIDTH} from '../constants';
import {formatDateTime, conventEnumValueToString, uuid, formatAmount} from '../utils';
import {addApplyReport, updateApplyReport, getDetail, getMarketingActivitySimple} from './api';
import TextInput from 'Shared/components/TextInput';
import SearchSelect from 'Shared/components/SearchSelect';
import MarketingActivitySelectPanel from './MarketingActivitySelectPanel';
import {currency, marketingActivityMainItem} from '../Enum';
import TagSelect from 'Shared/components/TagSelect';
import {injectIntl, language} from './intl';
import ItemTypeSelect from './ItemTypeSelect';
import WrappedSelect from '../common/WrappedSelect';
import LocalizeInputNumber from '../common/LocalizeInputNumber';
import styles from './style.css';
import Return from '../common/Return';
import FileUpload from './FileUpload';
const EMPTY_ARRAY = [];
import {newOrUpdateOrderValidator} from './validator';
const FormItem = Form.Item;

const marketingActivityMainItemToList = marketingActivityMainItem.toList(language);
class AddPanel extends React.PureComponent {
    state = {
        loading: false,
        hasOperat: false,
        isValidate: false,
        showMarketingActivitySelectPanel: false,
        data: {
            mainItem: [],
            actualMainItem: []
        },
        planItemDetails: [],
        actualItemDetails: [],
    }
    componentDidMount() {
        if(this.props.id) {
            this.setState({loading: true});
            getDetail(this.props.id)
                .then(res => {
                    if(res.ok)
                        this.setState({
                            loading: false,
                            data: res.data,
                            planItemDetails: res.data.planItemDetails.map(item => ({
                                itemtype: [
                                    item.marketingActivityItemCategoryL1Id,
                                    item.marketingActivityItemCategoryL2Id
                                ],
                                ...item
                            })),
                            actualItemDetails: res.data.actualItemDetails.map(item => ({
                                itemtype: [
                                    item.marketingActivityItemCategoryL1Id,
                                    item.marketingActivityItemCategoryL2Id
                                ],
                                ...item
                            })),
                        });
                    else
                        this.setState({loading: false});
                });
        }
    }
    componentWillUnmount() {
        this.isunmount = true;
    }
    // eslint-disable-next-line react/sort-comp
    onChange = (value, name) => {
        const data = Object.assign({}, this.state.data, {
            [name]: value
        });
        this.setState({
            data,
            hasOperat: true
        });
    }
    onClickOkOnPopconfirm = () => {
        this.props.onCancel();
    }
    onSubmit = () => {
        const data = this.state.data;
        const planItemDetails = this.state.planItemDetails;
        const actualItemDetails = this.state.actualItemDetails;
        const isValid = newOrUpdateOrderValidator(data, planItemDetails, actualItemDetails);
        if(!isValid) {
            this.setState({
                isValidate: true
            });
            return;
        }
        const addCondition = {
            marketingActivityId: data.marketingActivityId,
            brandId: data.brandId,
            mainItem: data.mainItem,
            mainItemRemark: data.mainItemRemark,
            actualMainItem: data.actualMainItem,
            actualMainItemRemark: data.actualMainItemRemark,
            scope: data.scope,
            customerQTY: data.customerQTY,
            amount: data.amount,
            actualCustomerQTY: data.actualCustomerQTY,
            totalFee: data.totalFee,
            actualSituation: data.actualSituation,
            opinion: data.opinion,
            planItemDetails: planItemDetails.map(y => ({
                marketingActivityItemCategoryId: y.itemtype ? y.itemtype.slice(-1)[0] : null,
                ...y
            })),
            actualItemDetails: actualItemDetails.map(y => ({
                marketingActivityItemCategoryId: y.itemtype ? y.itemtype.slice(-1)[0] : null,
                ...y
            })),
            attachmentPresentations: data.attachmentPresentations === undefined ? '' : data.attachmentPresentations.map(v => ({
                fileId: v.fileId,
                fileName: v.fileName
            }))
        };
        const updateCondition = {
            mainItemRemark: data.mainItemRemark,
            actualMainItemRemark: data.actualMainItemRemark,
            scope: data.scope,
            customerQTY: data.customerQTY,
            amount: data.amount,
            actualCustomerQTY: data.actualCustomerQTY,
            totalFee: data.totalFee,
            actualSituation: data.actualSituation,
            opinion: data.opinion,
            rowVersion: data.rowVersion,
            planItemDetails: planItemDetails.map(v => ({
                marketingActivityItemCategoryId: v.marketingActivityItemCategoryId,
                item: v.item,
                amount: v.amount,
                address: v.address,
                posts: v.posts,
                reading: v.reading,
                traffic: v.traffic,
                likes: v.likes,
                commentVolume: v.commentVolume,
                forwardingVolume: v.forwardingVolume,
                remark: v.remark,
            })),
            actualItemDetails: actualItemDetails.map(v => ({
                marketingActivityItemCategoryId: v.marketingActivityItemCategoryId,
                item: v.item,
                amount: v.amount,
                address: v.address,
                posts: v.posts,
                reading: v.reading,
                traffic: v.traffic,
                likes: v.likes,
                commentVolume: v.commentVolume,
                forwardingVolume: v.forwardingVolume,
                remark: v.remark,
            })),
            attachmentPresentations: data.attachmentPresentations === undefined ? '' : data.attachmentPresentations.map(v => ({
                fileId: v.fileId,
                fileName: v.fileName
            }))
        };
        this.setState({loading: true});
        if(data.id)
            updateApplyReport(this.props.id, updateCondition).then(res => {
                if(res.ok)
                    this.props.successReturn();
                if(!this.isunmount)
                    this.setState({loading: false});
            });
        else
            addApplyReport(addCondition).then(res => {
                if(res.ok)
                    this.props.successReturn();
                if(!this.isunmount)
                    this.setState({loading: false});
            });
    }
    onClickSearchMarketingActivityBtn = () => {
        this.setState({
            showMarketingActivitySelectPanel: true
        });
    }
    onCloseMarketingActivitySelectPanel = () => {
        this.setState({showMarketingActivitySelectPanel: false});
    }
    onSelectMarketingActivity = records => {
        const tmp = records.details.map(p => Object.assign({}, p, {
            num: p.num,
            marketingActivityItemId: p.id,
            marketingActivityItemCategoryL2Id: p.marketingActivityItemCategoryL2Id,
            item: p.item,
            amount: p.amount,
        }));
        this.setState({
            data: Object.assign({}, this.state.data, {
                marketingActivityId: records.id,
                marketingActivityCode: records.code,
                theme: records.theme,
                currency: records.currency,
                statDate: records.statDate,
                endDate: records.endDate,
                customerQTY: records.customerQTY,
                amount: records.amount,
            }),
            planItemDetails: tmp,
            actualItemDetails: tmp,
            hasOperat: true,
            showMarketingActivitySelectPanel: false
        });
    }
    onSearchMarketingActivity = value => getMarketingActivitySimple({
        filter: value,
    })
        .then(res => {
            const data = res.data;
            if(data)
                return data.content;
        })
    labelMap = d => {
        if(d.id === undefined)
            return '';
        if(d)
            return `${d.code}`;
        return '';
    }
    onDetailonChange = (value, name, id) => {
        const planItemDetails = this.state.planItemDetails || [];
        const tmp = planItemDetails.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    [name]: value ? value : ' ',
                });
            return d;
        });
        this.setState({
            planItemDetails: tmp,
            hasOperat: true
        });
    }
    onDetailonChanges = (value, name, id) => {
        const actualItemDetails = this.state.actualItemDetails || [];
        const tmp = actualItemDetails.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    [name]: value ? value : ' ',
                });
            return d;
        });
        this.setState({
            actualItemDetails: tmp,
            hasOperat: true
        });
    }
    
    removeFilePath = file => {
        const data = this.state.data;
        const index = data.attachmentPresentations.findIndex(item => item.fileId === file.fileId);
        if(index === -1)
            return null;
        const attachmentPresentations = data.attachmentPresentations || [];
        attachmentPresentations.splice(index, 1);
        this.setState({
            data: {
                ...data,
                attachmentPresentations
            },
            hasOperat: true,
        });
    }
    onClickAddDetl = () => {
        const actualItemDetails = this.state.actualItemDetails;
        this.setState({
            actualItemDetails: [
                ...actualItemDetails,
                {
                    id: uuid(),
                    itemtype: [],
                    item: '',
                    amount: 1,
                }
            ]
        });
    }
    onChangeUpload = value => {
        const data = this.state.data;
        const attachmentPresentations = data.attachmentPresentations || [];
        attachmentPresentations.push(value[0]);
        this.setState({
            data: {
                ...data,
                attachmentPresentations
            },
            hasOperat: true,
        });
    }
    onDeleteAll = () => {
        this.setState({
            actualItemDetails: [],
            hasOperat: true
        });
    }
    onDeleteDetail = e => {
        const id = e.target.dataset.id;
        const actualItemDetails = this.state.actualItemDetails.filter(p => p.id !== id);
        this.setState({
            actualItemDetails,
            hasOperat: true
        });
    }
    render() {
        const {formatMessage} = this.props.intl;
        const {data, planItemDetails, actualItemDetails, isValidate, loading} = this.state;
        const {brands} = this.props.initEnumData;
        if(brands.length === 1 && !this.props.id) {
            data.brandId = brands[0].value;
            data.brandName = brands[0].text;
        }
        const marketingActivityInfo = data.marketingActivityId ? {
            id: data.marketingActivityId,
            code: data.marketingActivityCode,
        } : null;
        const planItemDetailColumns = [{
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.num',
                defaultMessage: '序号'
            })}</span>,
            dataIndex: 'num',
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.marketingActivityItemCategoryL2Id',
                defaultMessage: '项目类型'
            })}</span>,
            dataIndex: 'itemtype',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <Form.Item {...validate}>
                        <ItemTypeSelect
                            name="itemtype"
                            defaultOption={{...record}}
                            value={text}
                            onChange={value => this.onDetailonChange(value, 'itemtype', record.id)}
                            changeOnSelect={true} />
                    </Form.Item>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.item',
                defaultMessage: '项目'
            })}</span>,
            dataIndex: 'item',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <TextInput
                            id={record.id}
                            name="item"
                            value={text}
                            onBlur={value => this.onDetailonChange(value, 'item', record.id)} />
                    </FormItem>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.amount',
                defaultMessage: '费用'
            })}</span>,
            dataIndex: 'amount',
            render: (text, record) => {
                const validate = (!text || text === undefined) && text !== 0 ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <LocalizeInputNumber
                            id={record.id}
                            value={text}
                            onChange={value => this.onDetailonChange(value, 'amount', record.id)} />
                    </FormItem>
                );
            }
        }, {
            title: formatMessage({
                id: 'addPanel.column.address',
                defaultMessage: '网址'
            }),
            dataIndex: 'address',
            render: (text, record) => (
                <FormItem>
                    <TextInput
                        id={record.id}
                        name="address"
                        value={text}
                        onBlur={value => this.onDetailonChange(value, 'address', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.posts',
                defaultMessage: '发帖量'
            }),
            dataIndex: 'posts',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChange(value, 'posts', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.reading',
                defaultMessage: '阅读量'
            }),
            dataIndex: 'reading',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChange(value, 'reading', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.traffic',
                defaultMessage: '点击量'
            }),
            dataIndex: 'traffic',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChange(value, 'traffic', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.likes',
                defaultMessage: '点赞量'
            }),
            dataIndex: 'likes',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChange(value, 'likes', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.commentVolume',
                defaultMessage: '评论量'
            }),
            dataIndex: 'commentVolume',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChange(value, 'commentVolume', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.forwardingVolume',
                defaultMessage: '转发量'
            }),
            dataIndex: 'forwardingVolume',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChange(value, 'forwardingVolume', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.remark',
                defaultMessage: '其它'
            }),
            dataIndex: 'remark',
            render: (text, record) => (
                <FormItem>
                    <TextInput
                        id={record.id}
                        name="remark"
                        value={text}
                        onBlur={value => this.onDetailonChange(value, 'remark', record.id)} />
                </FormItem>
            )
        }];
        const actualItemDetailColumns = [{
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.num',
                defaultMessage: '序号'
            })}</span>,
            dataIndex: 'num',
            render: (t, d, i) => i + 1
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.marketingActivityItemCategoryL2Id',
                defaultMessage: '项目类型'
            })}</span>,
            dataIndex: 'itemtype',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <Form.Item {...validate}>
                        <ItemTypeSelect
                            name="itemtype"
                            defaultOption={{...record}}
                            value={text}
                            onChange={value => this.onDetailonChanges(value, 'itemtype', record.id)}
                            changeOnSelect={true} />
                    </Form.Item>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.item',
                defaultMessage: '项目'
            })}</span>,
            dataIndex: 'item',
            render: (text, record) => {
                const validate = !text && isValidate ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <TextInput
                            id={record.id}
                            name="item"
                            value={text}
                            onBlur={value => this.onDetailonChanges(value, 'item', record.id)} />
                    </FormItem>
                );
            }
        }, {
            title: <span className="ant-form-item-required">{formatMessage({
                id: 'addPanel.column.amount',
                defaultMessage: '费用'
            })}</span>,
            dataIndex: 'amount',
            render: (text, record) => {
                const validate = (!text || text === undefined) && text !== 0 ? {validateStatus: 'error'} : null;
                return (
                    <FormItem {...validate}>
                        <LocalizeInputNumber
                            id={record.id}
                            value={text}
                            onChange={value => this.onDetailonChanges(value, 'amount', record.id)} />
                    </FormItem>
                );
            }
        }, {
            title: formatMessage({
                id: 'addPanel.column.address',
                defaultMessage: '网址'
            }),
            dataIndex: 'address',
            render: (text, record) => (
                <FormItem>
                    <TextInput
                        id={record.id}
                        name="address"
                        value={text}
                        onBlur={value => this.onDetailonChanges(value, 'address', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.posts',
                defaultMessage: '发帖量'
            }),
            dataIndex: 'posts',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChanges(value, 'posts', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.reading',
                defaultMessage: '阅读量'
            }),
            dataIndex: 'reading',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChanges(value, 'reading', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.traffic',
                defaultMessage: '点击量'
            }),
            dataIndex: 'traffic',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChanges(value, 'traffic', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.likes',
                defaultMessage: '点赞量'
            }),
            dataIndex: 'likes',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChanges(value, 'likes', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.commentVolume',
                defaultMessage: '评论量'
            }),
            dataIndex: 'commentVolume',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChanges(value, 'commentVolume', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.forwardingVolume',
                defaultMessage: '转发量'
            }),
            dataIndex: 'forwardingVolume',
            render: (text, record) => (
                <FormItem>
                    <LocalizeInputNumber
                        id={record.id}
                        value={text}
                        onChange={value => this.onDetailonChanges(value, 'forwardingVolume', record.id)} />
                </FormItem>
            )
        }, {
            title: formatMessage({
                id: 'addPanel.column.remark',
                defaultMessage: '其它'
            }),
            dataIndex: 'remark',
            render: (text, record) => (
                <FormItem>
                    <TextInput
                        id={record.id}
                        name="remark"
                        value={text}
                        onBlur={value => this.onDetailonChanges(value, 'remark', record.id)} />
                </FormItem>
            )
        }, {
            title: actualItemDetails.length > 0
                ? (
                    <Popconfirm placement="topRight" title={formatMessage({
                        id: 'addPanel.validation.isDelete',
                        defaultMessage: '是否确认全部删除？'
                    })} onConfirm={this.onDeleteAll} >
                        <a>{formatMessage({
                            id: 'addPanel.validation.clear',
                            defaultMessage: '清空'
                        })}</a>
                    </Popconfirm>
                )
                : null,
            dataIndex: 'id',
            fixed: 'right',
            width: FIXED_COLUMN_WIDTH,
            render: text => <a data-id={text} onClick={this.onDeleteDetail}>{formatMessage({
                id: 'addPanel.validation.delete',
                defaultMessage: '删除'
            })}</a>
        }];
        return (
            <div className="form-standard">
                <Spin spinning={this.state.loading}>
                    <Card title={formatMessage({
                        id: 'addPanel.column.common',
                        defaultMessage: '营销活动报告信息'
                    })}>
                        <Form>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.code',
                                        defaultMessage: '编号'
                                    })} {...FORM_OPTIONS.item}>
                                        {this.props.id
                                            ? data.code : <span className="value-font">{formatMessage({
                                                id: 'addPanel.value.defalut',
                                                defaultMessage: '尚未生成'
                                            })}</span>}
                                    </FormItem>
                                </Col>
                                {brands.length >= 1 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.brandName',
                                        defaultMessage: '品牌'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.brandId ? 'error' : null} required>
                                        {this.props.id
                                            ? `(${data.brandCode})${data.brandName}` : <WrappedSelect
                                                name="brandId"
                                                value={data.brandId}
                                                options={brands}
                                                onChange={this.onChange}/>}
                                    </FormItem>
                                </Col>}
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.data.marketingActivityId',
                                        defaultMessage: '营销活动编号'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.marketingActivityId ? 'error' : null} required>
                                        {this.props.id
                                            ? `${data.marketingActivityCode}` : <SearchSelect
                                                onSelect={this.onSelectMarketingActivity}
                                                onSearch={this.onSearchMarketingActivity}
                                                value={marketingActivityInfo}
                                                keyIndex="id"
                                                labelMap={this.labelMap}
                                                onClickSearchBtn={() => this.onClickSearchMarketingActivityBtn()} />}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.currency',
                                        defaultMessage: '币种'
                                    })} {...FORM_OPTIONS.item}>
                                        {conventEnumValueToString(currency, data.currency)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.theme',
                                        defaultMessage: '主题'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.theme}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.statDate',
                                        defaultMessage: '开始时间'
                                    })} {...FORM_OPTIONS.item}>
                                        {formatDateTime(data.statDate, DATETIME_FORMAT)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.endDate',
                                        defaultMessage: '结束时间'
                                    })} {...FORM_OPTIONS.item}>
                                        {formatDateTime(data.endDate, DATETIME_FORMAT)}
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'queryPanel.form.mainItem',
                                        defaultMessage: '计划主项目'
                                    })} {...FORM_ROW_OPTIONS.item} validateStatus={isValidate && !data.mainItem ? 'error' : null} required>
                                        {this.props.id
                                            ? data.mainItem.length > 0 && data.mainItem.map(item =>
                                                `${conventEnumValueToString(marketingActivityMainItem, item)}，`) : <TagSelect
                                                name="mainItem"
                                                value={data.mainItem}
                                                options={marketingActivityMainItemToList}
                                                onChange={this.onChange} />}
                                    </FormItem>
                                </Col>
                            </Row>
                            {data.mainItem && data.mainItem.indexOf(6) !== -1 && <Row className="row-margin">
                                <Col>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.mainItemRemark',
                                        defaultMessage: '计划主项目备注'
                                    })} {...FORM_ROW_OPTIONS.item} validateStatus={isValidate && !data.mainItemRemark ? 'error' : null} required>
                                        <TextInput
                                            name="mainItemRemark"
                                            type="textarea"
                                            value={data.mainItemRemark}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                            </Row>}
                            <Row>
                                <Col>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'queryPanel.form.actualMainItem',
                                        defaultMessage: '实际主项目'
                                    })} {...FORM_ROW_OPTIONS.item} validateStatus={isValidate && !data.actualMainItem ? 'error' : null} required>
                                        {this.props.id
                                            ? data.actualMainItem.length > 0 && data.actualMainItem.map(item =>
                                                `${conventEnumValueToString(marketingActivityMainItem, item)}，`) : <TagSelect
                                                name="actualMainItem"
                                                value={data.actualMainItem || []}
                                                options={marketingActivityMainItemToList}
                                                onChange={this.onChange} />}
                                    </FormItem>
                                </Col>
                            </Row>
                            {data.actualMainItem && data.actualMainItem.indexOf(6) !== -1 && <Row className="row-margin">
                                <Col>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.actualMainItemRemark',
                                        defaultMessage: '实际主项目备注'
                                    })} {...FORM_ROW_OPTIONS.item}
                                    validateStatus={isValidate && !data.actualMainItemRemark ? 'error' : null} required>
                                        <TextInput
                                            name="actualMainItemRemark"
                                            type="textarea"
                                            value={data.actualMainItemRemark}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                            </Row>}
                            <Row className="row-margin">
                                <Col>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.scope',
                                        defaultMessage: '营销目标'
                                    })} {...FORM_ROW_OPTIONS.item} validateStatus={isValidate && !data.scope ? 'error' : null} required>
                                        <TextInput
                                            name="scope"
                                            type="textarea"
                                            value={data.scope}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                            </Row>
                        </Form>
                    </Card>
                    <Card title={formatMessage({
                        id: 'addPanel.column.summarize',
                        defaultMessage: '活动总结'
                    })}>
                        <Form>
                            <Row className="row-margin">
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.customerQTY',
                                        defaultMessage: '目标用户量'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.customerQTY ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="customerQTY"
                                            value={data.customerQTY}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.amount',
                                        defaultMessage: '计划费用'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.amount ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="amount"
                                            value={data.amount}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.actualCustomerQTY',
                                        defaultMessage: '实际用户量'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.actualCustomerQTY ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="actualCustomerQTY"
                                            value={data.actualCustomerQTY}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.totalFee',
                                        defaultMessage: '实际费用'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.totalFee ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            name="totalFee"
                                            value={data.totalFee}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.actualSituation',
                                        defaultMessage: '完成情况'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.actualSituation ? 'error' : null} required>
                                        <TextInput
                                            name="actualSituation"
                                            value={data.actualSituation}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.operation.opinion',
                                        defaultMessage: '改善意见'
                                    })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.opinion ? 'error' : null} required>
                                        <TextInput
                                            name="opinion"
                                            value={data.opinion}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                            </Row>
                        </Form>
                    </Card>
                    <Card
                        title={formatMessage({
                            id: 'addPanel.operation.planItemDetails',
                            defaultMessage: '活动计划项目清单'
                        })}>
                        <Table
                            className="white-space-nowrap"
                            columns={planItemDetailColumns}
                            rowKey="id"
                            pagination={false}
                            dataSource={planItemDetails}
                            {...TABLE} />
                    </Card>
                    <Card
                        title={formatMessage({
                            id: 'addPanel.operation.actualItemDetails',
                            defaultMessage: '活动实际项目清单'
                        })}>
                        <Button
                            type="dashed"
                            icon="plus"
                            block
                            className={styles.plusBtn}
                            onClick={this.onClickAddDetl}>
                            {formatMessage({
                                id: 'newPanel.operation.new',
                                defaultMessage: '新增'
                            })}
                        </Button>
                        <Table
                            className="white-space-nowrap"
                            columns={actualItemDetailColumns}
                            rowKey="id"
                            pagination={false}
                            dataSource={actualItemDetails}
                            {...TABLE} />
                    </Card>
                    <Card title={formatMessage({
                        id: 'addPanel.title.files',
                        defaultMessage: '报告附件清单'
                    })}>
                        <Row>
                            <Col {...FORM_OPTIONS.col}>
                                <FileUpload onChange={this.onChangeUpload}
                                    onRemove={this.removeFilePath}
                                    fileList={data.attachmentPresentations || EMPTY_ARRAY}/>
                            </Col>
                        </Row>
                    </Card>
                    <Card className={styles.optionBtn}>
                        <Button
                            type="primary"
                            onClick={this.onSubmit}
                            loading={loading}>
                            {formatMessage({
                                id: 'addPanel.operation.onSubmit',
                                defaultMessage: '保存'
                            })}
                        </Button>
                    </Card>
                </Spin>
                {
                    this.state.showMarketingActivitySelectPanel &&
                    <MarketingActivitySelectPanel
                        selectKey={data.id}
                        onCancel={this.onCloseMarketingActivitySelectPanel}
                        onSelect={this.onSelectMarketingActivity} />
                }
                <div className="page-toolbar">
                    <Return
                        disabled={this.state.loading}
                        onConfirm={this.onClickOkOnPopconfirm}
                        showWarning={this.state.hasOperat} />
                </div>
            </div>
        );
    }
}

AddPanel.propTypes = {
    successReturn: PropTypes.func.isRequired,
    onCancel: PropTypes.func.isRequired,
    onSelect: PropTypes.func.isRequired,
    history: PropTypes.object,
    id: PropTypes.string,
    intl: PropTypes.object,
};

import {connect} from 'react-redux';
import {
    tableSearch,
    saveQueryDealer
} from './actions';
import {createSelector} from 'reselect';

const getinitEnumData = createSelector(
    state => state.getIn(['page', 'domainData', 'init']),
    init => {
        const initData = init.toJS();
        const brands = initData.brands ? initData.brands.map(item => ({
            text: `(${item.code})${item.name}`,
            value: item.id
        })) : [];
        return {
            brands,
        };
    }
);
const mapStateToProps = state => ({
    initEnumData: getinitEnumData(state),
});
const mapDispatchToProps = (dispatch, props) => ({
    onSelect: data => dispatch(saveQueryDealer(data)),
    successReturn: () => {
        dispatch(tableSearch());
        props.history.push(routes.query.url());
    },
    onCancel: () => {
        props.history.push(routes.query.url());
    },
});
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(AddPanel));
